<!--

    Copyright © 2016-2022 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<section class="tb-widget-settings" [formGroup]="analogueGaugeWidgetSettingsForm" fxLayout="column">
  <ng-container [ngSwitch]="gaugeType">
    <ng-container *ngSwitchCase="'radial'">
      <ng-container *ngTemplateOutlet="radialGauge; context: ctx "></ng-container>
    </ng-container>
    <ng-container *ngSwitchCase="'linear'">
      <ng-container *ngTemplateOutlet="linearGauge; context: ctx "></ng-container>
    </ng-container>
  </ng-container>
  <tb-color-input
    formControlName="defaultColor"
    icon="format_color_fill"
    label="{{ 'widgets.gauge.default-color' | translate }}" openOnInput colorClearButton>
  </tb-color-input>
  <fieldset class="fields-group">
    <legend class="group-title" translate>widgets.gauge.ticks-settings</legend>
    <section class="row-fill" fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="start center">
      <mat-form-field fxFlex class="mat-block">
        <mat-label translate>widgets.gauge.min-value</mat-label>
        <input matInput type="number" formControlName="minValue">
      </mat-form-field>
      <mat-form-field fxFlex class="mat-block">
        <mat-label translate>widgets.gauge.max-value</mat-label>
        <input matInput type="number" formControlName="maxValue">
      </mat-form-field>
    </section>
    <section fxLayout="column" fxLayout.gt-xs="row" fxLayoutGap="0px" fxLayoutGap.gt-xs="8px" fxLayoutAlign.gt-xs="start center">
      <mat-form-field fxFlex class="mat-block">
        <mat-label translate>widgets.gauge.major-ticks-count</mat-label>
        <input matInput type="number" min="0" formControlName="majorTicksCount">
      </mat-form-field>
      <tb-color-input fxFlex
                      formControlName="colorMajorTicks"
                      icon="format_color_fill"
                      label="{{ 'widgets.gauge.major-ticks-color' | translate }}" openOnInput colorClearButton>
      </tb-color-input>
    </section>
    <section fxLayout="column" fxLayout.gt-xs="row" fxLayoutGap="0px" fxLayoutGap.gt-xs="8px" fxLayoutAlign.gt-xs="start center">
      <mat-form-field fxFlex class="mat-block">
        <mat-label translate>widgets.gauge.minor-ticks-count</mat-label>
        <input matInput type="number" min="0" formControlName="minorTicks">
      </mat-form-field>
      <tb-color-input fxFlex
                      formControlName="colorMinorTicks"
                      icon="format_color_fill"
                      label="{{ 'widgets.gauge.minor-ticks-color' | translate }}" openOnInput colorClearButton>
      </tb-color-input>
    </section>
    <fieldset class="fields-group">
      <legend class="group-title" translate>widgets.gauge.tick-numbers-font</legend>
      <tb-widget-font formControlName="numbersFont"></tb-widget-font>
    </fieldset>
  </fieldset>
  <fieldset class="fields-group fields-group-slider">
    <legend class="group-title" translate>widgets.gauge.unit-title-settings</legend>
    <mat-expansion-panel class="tb-settings" [expanded]="analogueGaugeWidgetSettingsForm.get('showUnitTitle').value">
      <mat-expansion-panel-header fxLayout="row wrap">
        <mat-panel-title>
          <mat-slide-toggle formControlName="showUnitTitle" (click)="$event.stopPropagation()"
                            fxLayoutAlign="center">
            {{ 'widgets.gauge.show-unit-title' | translate }}
          </mat-slide-toggle>
        </mat-panel-title>
        <mat-panel-description fxLayoutAlign="end center" fxHide.xs translate>
          widget-config.advanced-settings
        </mat-panel-description>
      </mat-expansion-panel-header>
      <ng-template matExpansionPanelContent>
        <section fxLayout="column">
          <mat-form-field fxFlex class="mat-block">
            <mat-label translate>widgets.gauge.unit-title</mat-label>
            <input matInput formControlName="unitTitle">
          </mat-form-field>
          <fieldset class="fields-group">
            <legend class="group-title" translate>widgets.gauge.title-font</legend>
            <tb-widget-font formControlName="titleFont"></tb-widget-font>
          </fieldset>
        </section>
      </ng-template>
    </mat-expansion-panel>
  </fieldset>
  <fieldset class="fields-group">
    <legend class="group-title" translate>widgets.gauge.units-settings</legend>
    <fieldset class="fields-group">
      <legend class="group-title" translate>widgets.gauge.units-font</legend>
      <tb-widget-font formControlName="unitsFont"></tb-widget-font>
    </fieldset>
  </fieldset>
  <fieldset class="fields-group fields-group-slider">
    <legend class="group-title" translate>widgets.gauge.value-box-settings</legend>
    <mat-expansion-panel class="tb-settings" [expanded]="analogueGaugeWidgetSettingsForm.get('valueBox').value">
      <mat-expansion-panel-header fxLayout="row wrap">
        <mat-panel-title>
          <mat-slide-toggle formControlName="valueBox" (click)="$event.stopPropagation()"
                            fxLayoutAlign="center">
            {{ 'widgets.gauge.show-value-box' | translate }}
          </mat-slide-toggle>
        </mat-panel-title>
        <mat-panel-description fxLayoutAlign="end center" fxHide.xs translate>
          widget-config.advanced-settings
        </mat-panel-description>
      </mat-expansion-panel-header>
      <ng-template matExpansionPanelContent>
        <section fxLayout="column">
          <mat-form-field fxFlex class="mat-block">
            <mat-label translate>widgets.gauge.value-int</mat-label>
            <input matInput type="number" min="0" step="1" formControlName="valueInt">
          </mat-form-field>
          <fieldset class="fields-group">
            <legend class="group-title" translate>widgets.gauge.value-font</legend>
            <tb-widget-font formControlName="valueFont" [hasShadowColor]="true"></tb-widget-font>
          </fieldset>
          <section fxLayout="row wrap" fxLayoutGap="8px" fxLayoutAlign="start center">
            <tb-color-input fxFlex
                            formControlName="colorValueBoxRect"
                            icon="format_color_fill"
                            label="{{ 'widgets.gauge.value-box-rect-stroke-color' | translate }}" openOnInput colorClearButton>
            </tb-color-input>
            <tb-color-input fxFlex
                            formControlName="colorValueBoxRectEnd"
                            icon="format_color_fill"
                            label="{{ 'widgets.gauge.value-box-rect-stroke-color-end' | translate }}" openOnInput colorClearButton>
            </tb-color-input>
          </section>
          <section fxLayout="row wrap" fxLayoutGap="8px" fxLayoutAlign="start center">
            <tb-color-input fxFlex
                            formControlName="colorValueBoxBackground"
                            icon="format_color_fill"
                            label="{{ 'widgets.gauge.value-box-background-color' | translate }}" openOnInput colorClearButton>
            </tb-color-input>
            <tb-color-input fxFlex
                            formControlName="colorValueBoxShadow"
                            icon="format_color_fill"
                            label="{{ 'widgets.gauge.value-box-shadow-color' | translate }}" openOnInput colorClearButton>
            </tb-color-input>
          </section>
        </section>
      </ng-template>
    </mat-expansion-panel>
  </fieldset>
  <fieldset class="fields-group">
    <legend class="group-title" translate>widgets.gauge.plate-settings</legend>
    <tb-color-input fxFlex
                    formControlName="colorPlate"
                    icon="format_color_fill"
                    label="{{ 'widgets.gauge.plate-color' | translate }}" openOnInput colorClearButton>
    </tb-color-input>
    <mat-slide-toggle formControlName="showBorder">
      {{ 'widgets.gauge.show-plate-border' | translate }}
    </mat-slide-toggle>
  </fieldset>
  <fieldset class="fields-group">
    <legend class="group-title" translate>widgets.gauge.needle-settings</legend>
    <section fxLayout="row wrap" fxLayoutGap="8px" fxLayoutAlign="start center">
      <tb-color-input fxFlex
                      formControlName="colorNeedle"
                      icon="format_color_fill"
                      label="{{ 'widgets.gauge.needle-color' | translate }}" openOnInput colorClearButton>
      </tb-color-input>
      <tb-color-input fxFlex
                      formControlName="colorNeedleEnd"
                      icon="format_color_fill"
                      label="{{ 'widgets.gauge.needle-color-end' | translate }}" openOnInput colorClearButton>
      </tb-color-input>
    </section>
    <section fxLayout="row wrap" fxLayoutGap="8px" fxLayoutAlign="start center">
      <tb-color-input fxFlex
                      formControlName="colorNeedleShadowUp"
                      icon="format_color_fill"
                      label="{{ 'widgets.gauge.needle-color-shadow-up' | translate }}" openOnInput colorClearButton>
      </tb-color-input>
      <tb-color-input fxFlex
                      formControlName="colorNeedleShadowDown"
                      icon="format_color_fill"
                      label="{{ 'widgets.gauge.needle-color-shadow-down' | translate }}" openOnInput colorClearButton>
      </tb-color-input>
    </section>
  </fieldset>
  <fieldset class="fields-group">
    <legend class="group-title" translate>widgets.gauge.highlights-settings</legend>
    <mat-form-field fxFlex class="mat-block">
      <mat-label translate>widgets.gauge.highlights-width</mat-label>
      <input matInput type="number" min="0" formControlName="highlightsWidth">
    </mat-form-field>
    <fieldset class="fields-group">
      <legend class="group-title" translate>widgets.gauge.highlights</legend>
      <div fxLayout="column">
        <div class="tb-control-list tb-drop-list" cdkDropList cdkDropListOrientation="vertical"
             (cdkDropListDropped)="highlightDrop($event)">
          <div cdkDrag class="tb-draggable" *ngFor="let highlightControl of highlightsFormArray().controls; trackBy: trackByHighlightControl;
                 let $index = index; last as isLast;"
               fxLayout="column" [ngStyle]="!isLast ? {paddingBottom: '8px'} : {}">
            <tb-gauge-highlight [formControl]="highlightControl"
                                [expanded]="highlightControl.new"
                                (removeHighlight)="removeHighlight($index)">
            </tb-gauge-highlight>
          </div>
        </div>
        <div *ngIf="!highlightsFormArray().controls.length">
      <span translate fxLayoutAlign="center center"
            class="tb-prompt">widgets.gauge.no-highlights</span>
        </div>
        <div style="padding-top: 16px;">
          <button mat-raised-button color="primary"
                  type="button"
                  (click)="addHighlight()">
            <span translate>widgets.gauge.add-highlight</span>
          </button>
        </div>
      </div>
    </fieldset>
  </fieldset>
  <fieldset class="fields-group fields-group-slider">
    <legend class="group-title" translate>widgets.gauge.animation-settings</legend>
    <mat-expansion-panel class="tb-settings" [expanded]="analogueGaugeWidgetSettingsForm.get('animation').value">
      <mat-expansion-panel-header fxLayout="row wrap">
        <mat-panel-title>
          <mat-slide-toggle formControlName="animation" (click)="$event.stopPropagation()"
                            fxLayoutAlign="center">
            {{ 'widgets.gauge.enable-animation' | translate }}
          </mat-slide-toggle>
        </mat-panel-title>
        <mat-panel-description fxLayoutAlign="end center" fxHide.xs translate>
          widget-config.advanced-settings
        </mat-panel-description>
      </mat-expansion-panel-header>
      <ng-template matExpansionPanelContent>
        <section fxLayout="column">
          <mat-form-field fxFlex class="mat-block">
            <mat-label translate>widgets.gauge.animation-duration</mat-label>
            <input matInput type="number" min="0" formControlName="animationDuration">
          </mat-form-field>
          <mat-form-field fxFlex class="mat-block">
            <mat-label translate>widgets.gauge.animation-rule</mat-label>
            <mat-select formControlName="animationRule">
              <mat-option [value]="'linear'">
                {{ 'widgets.gauge.animation-linear' | translate }}
              </mat-option>
              <mat-option [value]="'quad'">
                {{ 'widgets.gauge.animation-quad' | translate }}
              </mat-option>
              <mat-option [value]="'quint'">
                {{ 'widgets.gauge.animation-quint' | translate }}
              </mat-option>
              <mat-option [value]="'cycle'">
                {{ 'widgets.gauge.animation-cycle' | translate }}
              </mat-option>
              <mat-option [value]="'bounce'">
                {{ 'widgets.gauge.animation-bounce' | translate }}
              </mat-option>
              <mat-option [value]="'elastic'">
                {{ 'widgets.gauge.animation-elastic' | translate }}
              </mat-option>
              <mat-option [value]="'dequad'">
                {{ 'widgets.gauge.animation-dequad' | translate }}
              </mat-option>
              <mat-option [value]="'dequint'">
                {{ 'widgets.gauge.animation-dequint' | translate }}
              </mat-option>
              <mat-option [value]="'decycle'">
                {{ 'widgets.gauge.animation-decycle' | translate }}
              </mat-option>
              <mat-option [value]="'debounce'">
                {{ 'widgets.gauge.animation-debounce' | translate }}
              </mat-option>
              <mat-option [value]="'delastic'">
                {{ 'widgets.gauge.animation-delastic' | translate }}
              </mat-option>
            </mat-select>
          </mat-form-field>
        </section>
      </ng-template>
    </mat-expansion-panel>
  </fieldset>
</section>

<ng-template #radialGauge let-settingsForm="settingsForm">
  <fieldset class="fields-group" [formGroup]="settingsForm">
    <legend class="group-title" translate>widgets.gauge.radial-gauge-settings</legend>
    <section class="row-fill" fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="start center">
      <mat-form-field fxFlex class="mat-block">
        <mat-label translate>widgets.gauge.start-ticks-angle</mat-label>
        <input matInput type="number" min="0" max="360" formControlName="startAngle">
      </mat-form-field>
      <mat-form-field fxFlex class="mat-block">
        <mat-label translate>widgets.gauge.ticks-angle</mat-label>
        <input matInput type="number" min="0" max="360" formControlName="ticksAngle">
      </mat-form-field>
    </section>
    <mat-form-field fxFlex class="mat-block">
      <mat-label translate>widgets.gauge.needle-circle-size</mat-label>
      <input matInput type="number" min="0" formControlName="needleCircleSize">
    </mat-form-field>
  </fieldset>
</ng-template>

<ng-template #linearGauge let-settingsForm="settingsForm">
  <fieldset class="fields-group" [formGroup]="settingsForm">
    <legend class="group-title" translate>widgets.gauge.linear-gauge-settings</legend>
    <section class="row-fill" fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="start center">
      <mat-form-field fxFlex class="mat-block">
        <mat-label translate>widgets.gauge.bar-stroke-width</mat-label>
        <input matInput type="number" min="0" formControlName="barStrokeWidth">
      </mat-form-field>
      <tb-color-input fxFlex
                      formControlName="colorBarStroke"
                      icon="format_color_fill"
                      label="{{ 'widgets.gauge.bar-stroke-color' | translate }}" openOnInput colorClearButton>
      </tb-color-input>
    </section>
    <section fxLayout="row wrap" fxLayoutGap="8px" fxLayoutAlign="start center">
      <tb-color-input fxFlex
                      formControlName="colorBar"
                      icon="format_color_fill"
                      label="{{ 'widgets.gauge.bar-background-color' | translate }}" openOnInput colorClearButton>
      </tb-color-input>
      <tb-color-input fxFlex
                      formControlName="colorBarEnd"
                      icon="format_color_fill"
                      label="{{ 'widgets.gauge.bar-background-color-end' | translate }}" openOnInput colorClearButton>
      </tb-color-input>
    </section>
    <section fxLayout="row wrap" fxLayoutGap="8px" fxLayoutAlign="start center">
      <tb-color-input fxFlex
                      formControlName="colorBarProgress"
                      icon="format_color_fill"
                      label="{{ 'widgets.gauge.progress-bar-color' | translate }}" openOnInput colorClearButton>
      </tb-color-input>
      <tb-color-input fxFlex
                      formControlName="colorBarProgressEnd"
                      icon="format_color_fill"
                      label="{{ 'widgets.gauge.progress-bar-color-end' | translate }}" openOnInput colorClearButton>
      </tb-color-input>
    </section>
  </fieldset>
</ng-template>
